#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    freopen("reputation.in", "r", stdin);
    freopen("reputation.out", "w", stdout);
    int n;
    cin >> n;
    vector<int> neg, pos;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x < 0)
            neg.push_back(x);
        else
            pos.push_back(x);
    }
    sort(neg.rbegin(), neg.rend());
    sort(pos.begin(), pos.end());
    int now = 0, time = 0, cost = 0;
    while (!(neg.empty() || pos.empty()))
    {
        int dl = now - neg.front(), dr = pos.front() - now;
        int cl = dl * pos.size(), cr = dr * neg.size();
        if (cl >= cr) // right
        {
            time += dr;
            now = pos.front();
            pos.erase(pos.begin());
            cost += time;
        }
        else
        {
            time += dl;
            now = neg.front();
            neg.erase(neg.begin());
            cost += time;
        }
    }
    while (!pos.empty())
    {
        time += pos.front() - now;
        now = pos.front();
        pos.erase(pos.begin());
        cost += time;
    }
    while (!neg.empty())
    {
        time += now - neg.front();
        now = neg.front();
        neg.erase(neg.begin());
        cost += time;
    }
    cout << cost << endl;
}
